/*
 * @author : TF-BJ-C064
 * @creation : 2014-8-11 下午8:57:12
 * @description : 
 *
 */

package com.action.park;

import java.io.PrintWriter;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.base.BaseAction;
import com.bean.HotAreaBean;
import com.bean.Location;
import com.service.HotAreaService;
import com.util.GUtil;

public class HotAreaAction extends BaseAction {

	private HotAreaService service ;
	private List<HotAreaBean> list;
	private List<Location> listCity;
	private String listCitys;
	private Integer cityId;

	@Override
	public String handle() throws Exception {
		//获取全国城市列表
		listCity = service.getCityList(null);
		listCitys = JSONArray.fromObject(listCity).toString();
		
		return GUtil.SUCCESS;
	}

	/**
	 * 热点地区分析
	 * <p>Title: query</p>
	 * <p>Description:
	 * 		统计各个停车场的订单总量，然后设定经纬度和count，利用百度热力图显示热点地区 hotAreaBean
	 * 		可以显示全国（按城市区分）、城市（按区域划分）、区（按停车场划分） cityid
	 * 		Referer：http://developer.baidu.com/map/jsdemo.htm#c1_15  百度热力图
	 *  </p>
	 * @return
	 * @throws Exception
	 * @see com.base.BaseAction#query()
	 */
	@Override
	public String query() throws Exception {

		list = service.query(cityId);
		
		JSONObject json = new JSONObject();
		if(list!=null && list.size()>0){
			String points = JSONArray.fromObject(list).toString();
			json.put("error", 0);
			json.put("data", points);
		}else{
			json.put("error", -1);
			json.put("msg", "暂无数据");
		}
		PrintWriter out =response.getWriter();
		out.write(json.toString());
		out.flush();
		out.close();

		return GUtil.NONE;
	}

	public String querySubCity() throws Exception {
		listCity = service.getCityList(cityId);
		JSONObject json = new JSONObject();
		if(list!=null && list.size()>0){
			String data = JSONArray.fromObject(listCity).toString();
			json.put("error", 0);
			json.put("data", data);
		}else{
			json.put("error", -1);
			json.put("msg", "暂无数据");
		}
		PrintWriter out =response.getWriter();
		out.write(json.toString());
		out.flush();
		out.close();
		return GUtil.NONE;
	}

	//deleted function blow

	@Deprecated
	@Override
	public String add() throws Exception {
		return null;
	}
	@Deprecated
	@Override
	public String update() throws Exception {
		return null;
	}
	@Deprecated
	@Override
	public String delete() throws Exception {
		return null;
	}
	@Deprecated
	@Override
	public String view() throws Exception {
		return null;
	}
	@Deprecated
	@Override
	public boolean validate(Object obj) throws Exception {
		return false;
	}

	public HotAreaService getService() {
		return service;
	}

	public void setService(HotAreaService service) {
		this.service = service;
	}

	public List<HotAreaBean> getList() {
		return list;
	}

	public void setList(List<HotAreaBean> list) {
		this.list = list;
	}

	public Integer getCityId() {
		return cityId;
	}

	public void setCityId(Integer cityId) {
		this.cityId = cityId;
	}

	public List<Location> getListCity() {
		return listCity;
	}

	public void setListCity(List<Location> listCity) {
		this.listCity = listCity;
	}

	public String getListCitys() {
		return listCitys;
	}

	public void setListCitys(String listCitys) {
		this.listCitys = listCitys;
	}

}
